<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/documentMyReady.js"></script>
    <style>
        .modal{
            display: flex;
            justify-content: center;
            align-items: center;
            flex-wrap: wrap;  
            position: fixed;
            left: 40%;
            top: 40%;
            width: 300px;
            height: 300px;
            background-color: #eee;
        }
        .modal-head, .modal-body, .modal-footer{
            width: 100%;
            text-align: center;
        }
        .modal .close{
            position: absolute;
            right: 0;
            top: 0;
        }
        .modal .close button{
            cursor: pointer;
        }
    </style>
    <script>
        document.myReady(function(){
            var modalEle = document.getElementsByClassName('modal')[0];
            var modalEleClose = modalEle.getElementsByTagName('button')[0];
            var modalBlock = document.getElementsByClassName('modal-block')[0];
            //隐藏
            modalEleClose.addEventListener('click',function(){
                modalEle.style.display = 'none';
            },false)
            //显示
            modalBlock.addEventListener('click',function(){
                modalEle.style.display = 'flex';
            },false)
        });
    </script>
</head>
<body>
    <button class="modal-block">显示</button>
    <div class="modal">
        <div class="close">
            <button>X</button>
        </div>
        <div class="modal-head">
            <p>modal-head</p>
        </div>
        <div class="modal-body">
            <p>modaybody</p>
        </div>
        <div class="modal-footer">
            <p>footer</p>
        </div>
    </div>
</body>
</html>